<%--
  Created by IntelliJ IDEA.
  User: Shuwei  Wang
  Date: 2020/6/16
  Time: 10:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--<!DOCTYPE html>--%>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局 - Layui</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">layui 后台布局</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="">控制台</a></li>
            <li class="layui-nav-item"><a href="">商品管理</a></li>
            <li class="layui-nav-item"><a href="">用户</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="">邮件管理</a></dd>
                    <dd><a href="">消息管理</a></dd>
                    <dd><a href="">授权管理</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    贤心
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="">退了</a></li>
        </ul>
    </div>


    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test" id="menu" <%-- lay-shrink="all"--%>>

            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">

            <div class="layui-tab" lay-allowClose="true" lay-filter="demo">  <%--重点重点重点--%>
                <ul class="layui-tab-title">
                    <li class="layui-this">欢迎页</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">欢迎！</div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>



<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
<script>
    //JavaScript代码区域

    layui.use(['element','layer','form','table'], function(){
        var element = layui.element;

        $(document).on("click",".test",function () {

            var title=$(this).html();//用户点击了哪个超链接
            var id=$(this).prop("id");//获取到用户点击的超链接的id属性值
            var url=$(this).attr("url");//获取到用户点击的超链接的id属性值

            if($("[lay-id="+id+"]").size()!=1) {
                //增加一个页签，layui会在html中添加一个标签<li layid=1>
                element.tabAdd("demo", {
                    title: title,
                    content:"<iframe frameborder='0' src='${pageContext.request.contextPath}"+url+"' style='width: 100%;height: 100%'></iframe>",
                    id: id  //生成的页面的属性lay-id=1
                });
            }
            element.tabChange("demo",id);
        });




        $.ajax({
            url:'${pageContext.request.contextPath}/menu/menuList'
            ,dataType:"json"
            ,type:'post'
            ,success:function (data) {
                var html="";
                $(data).each(function (i,o) {
                   html+=" <li class=\"layui-nav-item layui-nav-itemed\">\n" +
                       "                    <a class=\"\" href=\"javascript:;\">"+o.menuName+"</a><dl class=\"layui-nav-child\">";
                   $(o.menuList).each(function (i1,o1) {
                      html+= " <dd><a href=\"javascript:;\" class=\"test\"  id='"+o1.menuId+"' url='"+o1.menuUrl+"'>"+o1.menuName+"</a></dd>";
                   });
                   html+="    </dl>\n" +
                       "                </li>";
                });

                $("#menu").html(html);
                element.render("menu");

            }
        });








    });
</script>
</body>
</html>